$.extend(planner.dialogs, {
    importMech: {
        show: function()
        {
            $("#txtImportThisMechUrl" ).val("");
            $("#ImportThisMechError").css("display", "none");
            $( "#dialog-import-mech" ).dialog({
                height: 200,
                width: 620,
                modal: true,
            });    
        },
        ui:
        {
            init: function()
            {
                $('#txtImportThisMechUrl').keypress(function(e) {
                    if (e.keyCode == $.ui.keyCode.ENTER) {
                        planner.dialogs.importMech.import_mech();
                    }
                });
                $("#btnImportThisMech").button().click( planner.dialogs.importMech.import_mech );
                     
                $("#btnImportThisMechCancel").button().click(
                    function () {
                        $( "#dialog-import-mech" ).dialog("close");                
                    }
                );
                
                $(document).on("dialogopen", "#dialog-import-mech", function(event, ui) {
                    setTimeout(function() {
                        $("#txtImportThisMechUrl").focus();    
                    },100);
                });
            },
            setup: function()
            {
            },
        },
        import_mech: function(){
            console.log("planner.roster.import_mech()");
            $.ajax({ 
                url: "/m",
                dataType: 'json',
                type: "GET",
                data: { u: $("#txtImportThisMechUrl").val() }
            })
            .done( function(data) {
                console.log("planner.roster.import_mech: done()");
                
                if (data && data.mechtype ) {
                    planner.mech.speed = data.speed;
                    planner.mech.mechtype = data.mechtype ;
                    planner.mech.equipment = data.equipment;
                    planner.mech.weapons = data.weapons;
                    planner.mech.modules = [];
                //planner.drop.ui.update();
                    console.log("planner.roster.import_mech: done(): saving");
                    planner.mech.save();
                    $( "#dialog-import-mech" ).dialog("close"); 
                }
                else
                {
                    $("#ImportThisMechError").css("display", "block");
                }
                
                
            }).fail(function(){
                alert("bbad");
                $( "#dialog-import-mech" ).dialog("close"); 
            });
        }
        

    }
});